﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Configuration;
using System.Data.SqlServerCe;

namespace Randomizer
{
    /// <summary>
    /// Interaction logic for AddForm.xaml
    /// </summary>
    public partial class AddForm : Window
    {
        String _ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString;
        MainWindow mainWin;
       
        public AddForm(MainWindow mainWin)
        {
            InitializeComponent();
            this.mainWin = mainWin;
        }

        private void cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            SqlCeConnection _Conn = new SqlCeConnection(_ConnectionString);
            
            string query = "INSERT INTO Core_Table (Name,Weight,Cost,Book) VALUES ('" + name.Text + "', '" + weight.Text + "', '" + cost.Text + "', 'Custom')";
            
            SqlCeCommand comm = new SqlCeCommand(query, _Conn);

            //open db connection
            _Conn.Open();
            comm.ExecuteNonQuery();
            _Conn.Close();

            //Refresh CustomGrid
            mainWin.BindCustomGrid();
            this.Close();
        }
    }
}
